<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/messagebox.css?v=1">
<script type="text/javascript">

    $(function() {

        //初始化页面配置
        initPage("iowa支具留言");
        $("textarea").keypress(function(e) {
            if (e.which == 13) {
                return false;
            }
        });
        var app = new Vue({
            el: '#container',
            data: {
                info: [],
            },
            methods: {

                index: indexPage,
                cancel: function() {
                    window.location.href = "/wechat";
                },
                save: function() {

                    var messageId = $("input[name=messageId]").val();
                    var customerId = $("input[name=customerId]").val();
                    var number = $("input[name=number]").val();
                    var city = $("input[name=city]").val();
                    var productId = $("input[name=productId]").val();
                    var productName = $("input[name=productName]").val();
                    var wechatid = $("input[name=wechatid]").val();
                    var diagnosis = $("textarea[name=diagnosis]").val().replace(/[\r\n]/g,"。");
                    var messageContent = $("textarea[name=messageContent]").val().replace(/[\r\n]/g,"。");

                    if(isNullOrEmpty(city)) {
                        alert("请填写所在城市");
                        return false;
                    }

                    if(isNullOrEmpty(number)) {
                        alert("请填写联系电话");
                        return false;
                    }
                    if(!checkPhone(number)) {
                        alert("联系电话位数不对");
                        return false;
                    }

                    if(isNullOrEmpty(productId)) {
                        alert("请选择产品");
                        return false;
                    }
                    if(isNullOrEmpty(wechatid)) {
                        alert("请选择产品");
                        return false;
                    }
                    if(isNullOrEmpty(diagnosis)) {
                        alert("请填写症状或医生诊断");
                        return false;
                    }
                    if(confirm("请确认是否提交留言？")) {
                        $(".save-btn").hide();
                        $.ajax({
                            url: "/wechat/Messagebox/updateMessagebox",
                            type: "post",
                            data: {
                                messageId: messageId,
                                customerId: customerId,
                                city: city,
                                number: number,
                                productId: productId,
                                productName: productName,
                                wechatid: wechatid,
                                diagnosis: diagnosis,
                                messageContent: messageContent,
                            },

                            dataType: "JSON",
                            beforeSend: function () {
                                $("#loadingToast").show();
                            },
                            complete: function () {
                                $('#loadingToast').hide();
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    alert("提交成功");
                                    window.location.href = "/wechat/clubfoot/checkin";
                                }
                            },
                        })
                    }else{
                        return;
                    }
                }

            }
        })

        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("input[type=date]").change(function() {
            var value = $(this).val();
            $(this).prev().val(value);
        });

    });


</script>
<div class="hint-info">
    我们将在24小时内回复您的留言。
</div>
<div class="edit-content">
    <input type="text" style="display: none;" name="messageId" value="{$info.messagebox_id}">
    <input type="text" style="display: none;" name="customerId" value="{$customerId}">
    <div class="item">
        <span>产品</span>
        <input type="text" name="productName" value="{$ownProduct.product_name}" readonly>
        <input style="display: none" type="text" name="productId" value="{$ownProduct.product_id}" readonly>
        <!--<img class="icon-right disease" src="/Template/images/icon-right.png" alt="">-->
    </div>
    <div class="item">
        <span>所在城市</span>
        <input type="text" name="city" value="{$info.city}" placeholder="请填写您所在城市名称">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <div class="item">
        <span>联系电话</span>
        <input type="text" name="number" value="{$info.number}" placeholder="请填写您的电话号码">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <div class="item">
        <span>微信号</span>
        <input type="text" name="wechatid" value="{$info.wechatid}" placeholder="以便微信客服及时联系您">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <div class="title-span">
        <span>症状或医生诊断</span>
    </div>
    <div class="area">
        <textarea class="t-area" name="diagnosis" placeholder="请填症状或医生诊断">{$info.diagnosis}</textarea>
    </div>
    <div class="title-span">
        <span>留言</span>
    </div>
    <div class="area">
        <textarea class="t-area" name="messageContent" placeholder="请填写您的留言">{$info.message_content}</textarea>
    </div>
</div>

<div class="operation-btn">
    <div class="cancel-btn" v-on:click="cancel">取消</div>
    <div class="save-btn" v-on:click="save">提交</div>
</div>
<include file="./Template/footer.html" />

